from flask import Blueprint, session, request, url_for, redirect

admin_blu = Blueprint('admin',__name__,url_prefix='/admin')

from . import  views



@admin_blu.before_request
def check_admin():
    # if request.url.endswith(url_for('admin.login')):
    #     is_admin = session.get('is_admin',False)
    #     user_id = session.get('user_id',None)
    #     if not is_admin and  user_id:
    #         return redirect('/')
    is_admin = session.get('is_admin',False)
    if not is_admin and not request.url.endswith(url_for('admin.login')):
        return redirect('/')